package com.talent.codes.model;

public class PrintSetting {
    private int boxPadding = 8;
    /**竖向边距*/
    private int marginV = 58;
    /**横向边距*/
    private int marginH = 58;
    /**坑位宽*/
    private int imageW;
    private int imageH;

    private long firstId;
    private int idCnt;

    /**每行坑位*/
    private int columns;
    /**是否需要空盒子，即跳开部署*/
    private boolean emptyBox;
    /**竖向分割线，默认占位2px*/
    private boolean dividerV;
    /**横向分割线，默认占位2px*/
    private boolean dividerH;

    public PrintSetting() {
    }

    public PrintSetting(int imageW, int imageH, int columns) {
        this.imageW = imageW;  //左右 + 8 边距
        this.imageH = imageH;  //上下 + 8 边距
        this.columns = columns;
    }

    public PrintSetting margin(int marginH, int marginV) {
        this.marginH = marginH;
        this.marginV = marginV;
        return this;
    }

    public int boxPadding(){
        return boxPadding;
    }

    public void boxPadding(int boxPadding){
        this.boxPadding = boxPadding;
    }

    public PrintSetting idCtrl(long firstId, int idCnt){
        this.firstId = firstId;
        this.idCnt = idCnt;
        return this;
    }
    /**
     *  排版分隔设置
     * @param emptyBox 是否空位轮隔
     * @param dividerH 是否横向分割线
     * @param dividerV 是否纵向分割线
     * @return
     */
    public PrintSetting divide(boolean emptyBox, boolean dividerH, boolean dividerV) {
        this.emptyBox = emptyBox;
        this.dividerV = dividerV;
        this.dividerH = dividerH;
        return this;
    }

    public int getMarginV() {
        return marginV;
    }

    public void setMarginV(int marginV) {
        this.marginV = marginV;
    }

    public int getMarginH() {
        return marginH;
    }

    public void setMarginH(int marginH) {
        this.marginH = marginH;
    }

    public int getImageW() {
        return imageW;
    }

    public void setImageW(int imageW) {
        this.imageW = imageW;
    }

    public int getImageH() {
        return imageH;
    }

    public void setImageH(int imageH) {
        this.imageH = imageH;
    }

    public int getColumns() {
        return columns;
    }

    public void setColumns(int columns) {
        this.columns = columns;
    }

    public boolean isEmptyBox() {
        return emptyBox;
    }

    public boolean isEmptyBox(int rowIndex, int columnIndex) {
        int pos = rowIndex * columns + columnIndex;
        return emptyBox && pos % 2 == 1;
    }

    public void setEmptyBox(boolean emptyBox) {
        this.emptyBox = emptyBox;
    }

    public boolean isDividerV() {
        return dividerV;
    }

    public void setDividerV(boolean dividerV) {
        this.dividerV = dividerV;
    }

    public boolean isDividerH() {
        return dividerH;
    }

    public void setDividerH(boolean dividerH) {
        this.dividerH = dividerH;
    }

    public long getFirstId() {
        return firstId;
    }

    public void setFirstId(long firstId) {
        this.firstId = firstId;
    }

    public int getIdCnt() {
        return idCnt;
    }

    public void setIdCnt(int idCnt) {
        this.idCnt = idCnt;
    }

    public int pageWidth(){
        int pd = boxPadding * 2;
        return marginH * 2 + (imageW + pd) * columns;
    }


    public int pageLines(){
        int lines = 0;
        if(emptyBox){
            //需要空位轮隔
            if(columns % 2 > 0){
                //单数
                lines = idCnt / columns * 2;
                int dls = idCnt - lines / 2 * columns; //看看双行个数
                if(dls>0){
                    lines ++;
                }
            }else{
                //双数
                int colHalf = columns / 2;
                lines = idCnt / colHalf;
                if(idCnt % colHalf > 0){
                    lines++;
                }
            }
        }else{
            //不需要空位轮隔
            lines = idCnt / columns;
            if(idCnt % columns > 0){
                lines++;
            }
        }
        return lines;
    }

    public int pageHeight(){
        int pd = boxPadding * 2;
        int lines = pageLines() - 1;
        int sglBoxH = imageH + pd;

        int boxH = boxHeight();
        return marginV * 2 + boxH * lines + sglBoxH;
    }

    public int boxWidth(){
        int pd = boxPadding * 2;
        return imageW + pd;
    }

    public int boxHeight(){
        int pd = boxPadding * 2;
        return emptyBox && !dividerH ? imageH/10*7 + pd : imageH + pd;
    }
}
